package nio.buffer;

import java.nio.ByteBuffer;

/**
 * 只读Buffer，只能读，不能写
 */
public class ReadOnlyBuffer {
    public static void main(String[] args) {
        ByteBuffer byteBuffer = ByteBuffer.allocate(64);

        for (int i = 0 ; i < byteBuffer.capacity() ; i++){
            byteBuffer.put((byte) i);
        }

        byteBuffer.flip();

        /**
         * 转换为一个只读buffer
         */
        ByteBuffer readOnlyBuffer = byteBuffer.asReadOnlyBuffer();

        while (readOnlyBuffer.hasRemaining()){
            System.out.println(readOnlyBuffer.get());
        }
    }
}
